# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=cmake
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.6.1
pkgrel=1
pkgdesc="A cross-platform open-source make system (mingw-w64)"
arch=('any')
url="https://www.cmake.org/"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-qt5")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-jsoncpp"
         "${MINGW_PACKAGE_PREFIX}-libarchive"
         "${MINGW_PACKAGE_PREFIX}-zlib")
optdepends=("${MINGW_PACKAGE_PREFIX}-qt5: CMake Qt GUI")
options=('staticlibs') # '!strip' 'debug'
source=("https://www.cmake.org/files/v${pkgver%.*}/${_realname}-${pkgver}.tar.gz"
        "0001-Disable-response-files-for-MSYS-Generator.patch"
        "dont-install-bundle.patch"
        "0002-Implement-Qt5-static-plugin-support.patch"
        "pkg-config-without-prefix.patch"
        "do-not-generate-import-library-for-executables.patch")
sha256sums=('28ee98ec40427d41a45673847db7a905b59ce9243bb866eaf59dce0f58aaef11'
            'ce17e87849e6d07cf69422bb39c0682640ed3a03ea07808395c235a84e22be97'
            'aa816b734bf91941403b25bc9d9fd1797675ce2b4a7311bdb6e3ecae38964c37'
            'd78e30b4e0e8c1fc449acff5ea910c4691edd1ca2be60141ad7d3dd9a11ce6b9'
            'aa807e20e4a2902a8e6f3f36e1cd7d4b043d0df12f4fb0f4e6bd27d9d6842c0f'
            '8503536bfc6606e147c62cd7bc28f984911a04b7bf8164264c345eacbf68dc5b')

prepare() {
  cd ${_realname}-${pkgver}
  patch -Np1 -i ${srcdir}/0001-Disable-response-files-for-MSYS-Generator.patch
  patch -Np1 -i ${srcdir}/dont-install-bundle.patch
  patch -Np1 -i ${srcdir}/0002-Implement-Qt5-static-plugin-support.patch
  patch -Np1 -i ${srcdir}/pkg-config-without-prefix.patch
  patch -Np1 -i ${srcdir}/do-not-generate-import-library-for-executables.patch
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYSTEM=MINGW "${srcdir}"/${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --system-libs \
    --no-system-expat \
    --qt-gui \
    --parallel=3 \
    --mandir=share \
    --docdir=share/doc/cmake

  plain "Start building..."
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  ./bin/cmake.exe -DCMAKE_INSTALL_PREFIX:PATH=${pkgdir}${MINGW_PREFIX} -P cmake_install.cmake
}
